Repository navigation
csdb: reject pools whose hashing length points past their data (OOB read) - #5
Merged
Merged
Conversation
Pool::from_binary(), Pool::hash_from_binary() and Pool::from_lz4_byte_stream() read hashingLength_ from the bytes being parsed, then updateHash() hashes hashingLength_ bytes of them. Nothing checked that the length fits, so a peer-supplied block (e.g. a BlockReply while syncing) with a large hashing length makes the node read past the buffer: SIGSEGV, or a hash over unrelated memory. Reject such data in the three entry points that know the full buffer size, with the same result as any other parse error: an invalid Pool or an empty PoolHash. A legitimate pool cannot be affected: hashingLength_ is, by construction, the size of the pool's own serialized prefix (Pool::priv::put), so it is always smaller than the pool's data. Note: the check cannot live in get_hashed_data(), because ibstream::size() is the number of bytes still unread, not the total size. A first attempt there rejected valid pools, and the PoolCache serialization tests caught it. Tests (tests/csnode/pool_tests.cpp): - Pool.RejectsHashingLengthPastData: before the fix it crashes with SIGSEGV. - Pool.AcceptsSerializedPool: guards against rejecting valid pools. nodetests: 112/112 pass. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem: out-of-bounds read on block data received from the network
Pool::from_binary(),Pool::hash_from_binary()andPool::from_lz4_byte_stream()readhashingLength_from the bytes being parsed, thenupdateHash()hashes that many bytes. Nothing checked that the length fits inside the data.A peer-supplied block (e.g. a
BlockReplywhile syncing) with a huge hashing length makes the node read past its buffer: SIGSEGV, or a hash computed over unrelated memory.Fix (
csdb/src/pool.cpp, +16/-2)Such data is rejected in the three entry points that know the full buffer size, with the same result as any other parse error: an invalid
Poolor an emptyPoolHash.A legitimate block cannot be affected: by construction,
hashingLength_is the size of the block's own serialised prefix (Pool::priv::put), so it is always smaller than the data.Tests (
tests/csnode/pool_tests.cpp)Pool.RejectsHashingLengthPastDataPool.AcceptsSerializedPool(false-positive guard)nodetestsUpstream
A single commit that applies as is to CREDITSCOM/node, where
pool.cppis identical. It is independent of PR #4 (Compressor), although together they close theBlockReply-> crash path.🤖 Generated with Claude Code